from django.contrib.auth.models import AbstractUser, UserManager
from django.db import models

# Create your models here.


class BaseModel(models.Model):
    create_time = models.DateField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateField(auto_now=True, verbose_name="更新时间")

    class Meta:
        abstract = True


class User(AbstractUser):
    """用户模型类"""
    mobile = models.CharField(max_length=11, null=True, unique=True, verbose_name='手机号')
    avatar = models.ImageField(upload_to='avatar', max_length=256, null=True, verbose_name='用户头像')
    intro = models.CharField(max_length=256, null=True, verbose_name="用户简介")
    city = models.CharField(max_length=64, null=True, verbose_name='现居地址')
    school = models.CharField(max_length=32, null=True, verbose_name="毕业学校")
    company = models.CharField(max_length=32, null=True, verbose_name="公司")
    website = models.CharField(max_length=64, null=True, verbose_name='个人网站')
    specialities = models.CharField(max_length=16, null=True, verbose_name="专业", default='')
    position = models.CharField(max_length=16, null=True, verbose_name="职位", default='')

    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name


class Archives(BaseModel):
    """用户档案类"""
    GENDER_CHOICES = (
        (0, '男'),
        (1, '女')
    )
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    name = models.CharField(max_length=64, null=True, verbose_name='真实姓名')
    gender = models.SmallIntegerField(null=True, choices=GENDER_CHOICES, verbose_name='性别')
    birthdate = models.DateField(null=True, verbose_name="出生年月")
    adderss = models.CharField(max_length=64, null=True, verbose_name='居住地址')
    avatar = models.ImageField(max_length=64, null=True, default='', verbose_name='用户头像')

    class Meta:
        db_table = 'tb_user_archives'
        verbose_name = '档案'
        verbose_name_plural = verbose_name


class Technology(BaseModel):
    """用户技能表"""

    name = models.CharField(max_length=32, null=True, verbose_name="技能名称")

    class Meta:
        db_table = 'tb_user_technology'
        verbose_name = '技能'
        verbose_name_plural = verbose_name


class Good(models.Model):
    """用户擅长技能"""
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    technology_id = models.ForeignKey(Technology, on_delete=models.PROTECT, verbose_name='用户')

    class Meta:
        db_table = 'tb_user_goods'
        verbose_name = '擅长技能'
        verbose_name_plural = verbose_name


class Jobs(BaseModel):
    """工作经历"""

    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    company = models.CharField(max_length=16, null=True, verbose_name="公司名称")
    position = models.CharField(max_length=16, null=True, verbose_name="职位")
    work_time = models.CharField(max_length=16, null=True, verbose_name='工作时间')

    class Meta:
        db_table = 'tb_user_jobs'
        verbose_name = '工作经历'
        verbose_name_plural = verbose_name


class Educational(BaseModel):
    """教育经历"""

    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    school = models.CharField(max_length=16, null=True, verbose_name="学校名称")
    specialities = models.CharField(max_length=16, null=True, verbose_name="专业")
    study_time = models.CharField(max_length=16, null=True, verbose_name='学习时间')

    class Meta:
        db_table = 'tb_user_educational'
        verbose_name = '教育经历'
        verbose_name_plural = verbose_name


class Account(BaseModel):
    MODE_CHOICES = (
        ('0', 'QQ'),
        ('1', '微信'),
        ('3', '微博')
    )
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='用户')
    account = models.CharField(max_length=16, null=True, verbose_name="账号")
    mode = models.SmallIntegerField(null=True, choices=MODE_CHOICES, verbose_name="账号类型")
    is_dispaly = models.BooleanField(default=False, verbose_name="是否显示")

    class Meta:
        db_table = 'tb_user_account'
        verbose_name = '绑定账号'
        verbose_name_plural = verbose_name
